<template>
  <div class="h100 commonTableSty" ref="tasksInVehicleTableList">
    <s-table
      :columns="columns"
      :data-source="lists"
      :loading="loading"
      :pagination="false"
      class="h100"
      :row-key="(record) => record.taskId"
      :rowSelection="{
        selectedRowKeys: selectedRowKeys,
        onChange: onSelectChange,
        columnWidth: 40,
        getCheckboxProps: onGetCheckboxProps,
      }"
    >
      <template #campaignName="text">
        <table-ellipsis :text="text"></table-ellipsis>
      </template>
      <template #isTestTask="text">
        <span>{{ $t(text >=8 ? 'yes' : 'no') }}</span>
      </template>
      <template #status="text">
        <span>{{ taskVehicleStatusDictCodeObj[text] || '-' }}</span>
      </template>
    </s-table>
  </div>
</template>
<script>
import { tasksInVehicleTbColumns } from './config/list'
import tableEllipsis from '@/components/Ellipsis/TableEllipsis'
import taskApi from '@/api/modules/task'
import { STable } from '@/components'
export default {
  components: {
    tableEllipsis,
    STable
  },
  mixins: [],
  props: {
    query: {
      type: Object,
      default () {
        return null
      }
    }
  },
  computed: {
    taskVehicleStatusDictCodeObj () {
      return this.$store.getters.getDictCodeObj('taskVehicleStatusDictCode')
    }
  },
  data () {
    return {
      columns: tasksInVehicleTbColumns,
      downing: false,
      lists: [],
      loading: false,
      selectedRowKeys: []
    }
  },
  created () {
    this.getPageDictData()
    this.getData()
  },
  methods: {
    onGetCheckboxProps: (record) => ({
      // 是正式任务不能被选择
      props: {
        disabled: record.taskType <= 2 || record.channel === 0
      }
    }),
    getData () {
      if (!this.query || !this.query.vehicleId) {
        this.lists = []
        return
      }
      this.loading = true
      taskApi
        .getVehicleOccupiedDetailLists(this.query)
        .then((res) => {
          console.log(res, '020020')
          this.lists = res.data.map((item) => {
            return {
              taskId: item.taskId,
              taskName: item.taskName,
              taskType: item.taskType,
              channel: item.channel,
              status: item.status
            }
          })
        })
        .finally(() => {
          this.loading = false
        })
    },
    onSelectChange (selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    getSaveData () {
      return {
        taskIds: this.selectedRowKeys
      }
    },
    getPageDictData () {
      ;['getTaskVehicleStatusDictCodeData'].forEach((method) => {
        this.$store.dispatch(method)
      })
    }
  }
}
</script>
